// product/pages/topicList/topicList.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    total:0,
    currentPage:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getTopicList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  // 页面上拉触底事件（上拉加载更多）
  onReachBottom: function () {
    console.log('222====');
    const { total, list, currentPage } = this.data
    if (Number(total) > list.length) {
      console.log('222====!!!!!');
      this.setData({
        currentPage: currentPage + 1
      })
      this.getTopicList()
    }
 },
  getTopicList() {
    const { currentPage } = this.data
    app.api.post({
      url: "audio_course_vx_page",
      data:{
        currentPage:this.data.currentPage,
        pageSize:15
      }
    }).then(res=>{
      let { list } = this.data
      currentPage === 1 ? (list = res.list) : list.push(...res.list)
      this.setData({ list, total: res.total })
    })
  },
  goDetail (e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/product/pages/audioCourse/audioCourse?id=${id}`,
    });
  }
})